#include <webhttpd/Basic.h>

#include <srclink/frontend.h>
#include <srclink/static_response.h>

// 配置前端
void init_frondend() {
    add_route("^/static/.*$", &static_response);  // 资源文件
    add_route("^/$", &index_route);  // 主页
    add_route("^/add$", &add_student_route);  // 添加页面
    add_route("^/edit$", &edit_student_route);  // 编辑页面
    add_route("^/stat$", &stat_route);  // 年龄统计
}

// 基本模板
// HttpResponse response;
// response.status_code = 200;
// response.headers = g_hash_table_new(g_str_hash, g_str_equal);
//
// g_hash_table_insert(response.headers, "Content-Type", "text/html; charset=utf-8");
//
// response.body.content = malloc(100);
// response.body.size = strlen("Hello, world.") + 1;
// strcpy(response.body.content, "Hello, world.");

HttpResponse index_route(HttpRequest request) {
    return send_template(request, "index.html");
}

HttpResponse add_student_route(HttpRequest request) {
    return send_template(request, "add.html");
}

HttpResponse edit_student_route(HttpRequest request) {
    return send_template(request, "edit.html");
}

HttpResponse stat_route(HttpRequest request) {
    return send_template(request, "stat.html");
}

